package com.yuanfeng.userms.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.update.LambdaUpdateWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yuanfeng.commoms.util.ResponseResult;
import com.yuanfeng.userms.entity.UserTreasureEntity;
import com.yuanfeng.userms.mapper.UserTreasureMapper;
import com.yuanfeng.userms.service.UserTreasureService;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 *
 */
@Service
public class UserTreasureServiceImpl extends ServiceImpl<UserTreasureMapper, UserTreasureEntity>
    implements UserTreasureService{

    @Override
    public ResponseResult update(Map<String, Object> map) {
        UserTreasureEntity entity=this.baseMapper.selectOne(new LambdaQueryWrapper<UserTreasureEntity>()
                                    .eq(UserTreasureEntity::getUserId,map.get("userId").toString())
                                    .eq(UserTreasureEntity::getShopId,map.get("shopId").toString()));
       int flag=this.baseMapper.update(null,new LambdaUpdateWrapper<UserTreasureEntity>()
                .eq(UserTreasureEntity::getUserId,map.get("userId").toString())
                .eq(UserTreasureEntity::getShopId,map.get("shopId").toString())
                .set(UserTreasureEntity::getNumberOfGifts,entity.getNumberOfGifts()-Integer.valueOf(map.get("numberOfGifts").toString())));
        return ResponseResult.success();
    }
}




